#ifndef TOOLS_CHEAP_H_
#define TOOLS_CHEAP_H_

#include<stdlib.h>
//#include<string.h>

#include<tools/lb_memory.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct CHeap{
    //用来标记最大堆或者最小堆
    //0 是最小堆
    //1 是最大堆
    int mark;
    void** values;
    //int width;
    int (*comp)(const void*v1,const void*v2);
    //堆的元素个数
    int size;  
    int max_size;
    void* prop;
}CHeap;


static inline void cheap_init(CHeap* ch)
{   
    ch->mark=0;
    ch->values=NULL;
    //ch->width=4;
    ch->comp=NULL;
    ch->size=0;
    ch->max_size=0;
    ch->prop=NULL;
}

static inline void cheap_free(CHeap* ch)
{
    if(ch==NULL){return;}
    if(ch->values!=NULL){LB_FREE(ch->values);ch->values=NULL;}
    LB_FREE(ch);
}


void make_min_cheapi(CHeap* ch,int index);
//void make_min_cheap(CHeap*ch);



void make_max_cheapi(CHeap* ch,int index);
//void make_max_cheap(CHeap*ch);

void make_cheap(CHeap*ch);


void* pop_cheap(CHeap*ch);

int insert_cheap(CHeap*ch,void*value);





#ifdef __cplusplus
}
#endif

#endif